<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/16.8.4/umd/react.development.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/16.8.4/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.8.1/prop-types.js"></script>
  </head>
  <body>
    <div id="test"></div>
    <script type="text/babel">
      class Dog extends React.Component {
        container1 = React.createRef();
        container2 = React.createRef();
        state = {
          name: "zs",
          pwd: "456",
        };
        submit = (e) => {
          e.preventDefault();
          console.log(this.container1);
          console.log(this.container2);
        };
        saveUsername = (e) => {
          this.setState({
            name: e.target.value,
          });
        };
        render() {
          return (
            <div>
              <h1>表单</h1>
              <form onSubmit={this.submit}>
                <label htmlFor="ipt">用户名</label>
                {/*<input type="text" id="ipt" ref={this.container1} />*/}
                <input type="text" id="ipt" onChange={this.saveUsername} />
                <label htmlFor="pwd">密码</label>
                {/*<input type="password" id="pwd" ref={this.container2} />*/}
                <input type="password" id="pwd" ref={this.container2} />
                <button>登录</button>
              </form>
            </div>
          );
        }
      }
      ReactDOM.render(<Dog />, document.getElementById("test"));
    </script>
  </body>
</html>
